/*

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; version 2
 of the License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
#import "PlaybackControlView.h"
#import "PlaybackControlObserver.h"
#import "XBMCControlApplication.h"
#import "XBMCHttpInterface.h"
#import "IconManager.h"
//#import <UIKit/UIColor.h>


@implementation PlaybackControlView

- (id) initWithObserver: (id <PlaybackControlObserver>) observer withFrame: (struct CGRect)rect
{
    self = [super initWithFrame: rect];
	m_rect = rect;
	m_xbmc = [XBMCHttpInterface sharedInstance];
	m_observer = observer;

	// need header file UIColor.h for this to work....
	//self.backgroundColor = [UIColor tableBackgroundColor];  
	
	
	c_prevNextButtonSize = 60.0f;
	c_playPauseButtonSize = 79.0f;
	
	// push buttons

	// prev track
	m_prevTrackButton = [[UIPushButton alloc] initWithTitle:@"" autosizesToFit:NO];
	[m_prevTrackButton setFrame: CGRectMake((rect.size.width/2 - c_playPauseButtonSize/2 - c_prevNextButtonSize - 4) , rect.size.height - c_playPauseButtonSize +(c_playPauseButtonSize - c_prevNextButtonSize)/2, c_prevNextButtonSize, c_prevNextButtonSize)];
	[m_prevTrackButton setDrawsShadow: YES];
	[m_prevTrackButton setEnabled:YES];  //may not be needed
	[m_prevTrackButton setStretchBackground:YES];

	[m_prevTrackButton setBackground:[[IconManager sharedInstance] getPrevTrackIcon] forState:0];  //up state
	[m_prevTrackButton setBackground:[[IconManager sharedInstance] getPrevTrackIcon_Pressed] forState:1]; //down state
	[m_prevTrackButton addTarget:self action:@selector(prevTrackSelected) forEvents:(64)];
	[self addSubview: m_prevTrackButton];
	
	// play pause
	m_playPauseButton = [[UIPushButton alloc] initWithTitle:@"" autosizesToFit:NO];
	[m_playPauseButton setFrame: CGRectMake(rect.size.width/2 - c_playPauseButtonSize/2, rect.size.height - c_playPauseButtonSize, c_playPauseButtonSize, c_playPauseButtonSize)];
	[m_playPauseButton setDrawsShadow: YES];
	[m_playPauseButton setEnabled:YES];  //may not be needed
	[m_playPauseButton setStretchBackground:YES];

	[m_playPauseButton setBackground:[[IconManager sharedInstance] getPlayPauseIcon] forState:0];  //up state
	[m_playPauseButton setBackground:[[IconManager sharedInstance] getPlayPauseIcon_Pressed] forState:1]; //down state
	[m_playPauseButton addTarget:self action:@selector(playPauseSelected) forEvents:(64)];
	[self addSubview: m_playPauseButton];
	
	// next track
	m_nextTrackButton = [[UIPushButton alloc] initWithTitle:@"" autosizesToFit:NO];
	[m_nextTrackButton setFrame: CGRectMake(rect.size.width/2 + c_playPauseButtonSize/2 + 4, rect.size.height - c_playPauseButtonSize +(c_playPauseButtonSize - c_prevNextButtonSize)/2, c_prevNextButtonSize, c_prevNextButtonSize)];
	[m_nextTrackButton setDrawsShadow: YES];
	[m_nextTrackButton setEnabled:YES];  //may not be needed
	[m_nextTrackButton setStretchBackground:YES];

	[m_nextTrackButton setBackground:[[IconManager sharedInstance] getNextTrackIcon] forState:0];  //up state
	[m_nextTrackButton setBackground:[[IconManager sharedInstance] getNextTrackIcon_Pressed] forState:1]; //down state
	[m_nextTrackButton addTarget:self action:@selector(nextTrackSelected) forEvents:(64)];
	[self addSubview: m_nextTrackButton];

	return self;
}

- (int) getHeight
{
	return c_playPauseButtonSize;
}

- (int) getWidth
{
	return m_rect.size.width;
}

- (void) playPauseSelected
{
	[m_observer showProgress: YES];
	[m_xbmc pause];
	[m_observer observePlayPause];
	[m_observer showProgress: NO];
}

- (void) nextTrackSelected
{
	[m_observer showProgress: YES];
	[m_xbmc playNext];
	[m_observer observeNextTrack];
	[m_observer showProgress: NO];
}

- (void) prevTrackSelected
{
	[m_observer showProgress: YES];
	[m_xbmc playPrev];
	[m_observer observePrevTrack];
	[m_observer showProgress: NO];
}

-(void)dealloc
{
   [super dealloc];
}


@end

